package cn.edu.zust.se.hellodubbo.controller;

import cn.edu.zust.se.hellodubbo.dto.UserDto;
import cn.edu.zust.se.hellodubbo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("users")
@Slf4j
public class UserController {
    @DubboReference(version = "${hello.service.version}")
    UserService userService;
    @PostMapping("")
    public UserDto addUser(@RequestBody UserDto user){
        return userService.addUser(user);
    }
    @GetMapping("/{id}")
    public UserDto getUserById(@PathVariable("id") Integer id){
        log.debug("get user id="+id);
        return userService.getUserById(id);
    }
    @GetMapping("")
    public List<UserDto> getAllUsers(){
        return userService.findAll();
    }
    @PostMapping("login")
    public UserDto login(@RequestBody UserDto user){
        return userService.login(user);
    }
}
